﻿using System;
using System.ComponentModel;
using System.Xml.Serialization;

namespace Interscape.TwilioClient.Components
{

    /// <summary>
    /// A paged collection of <see cref="PhoneCall">PhoneCall</see> objects.
    /// </summary>
    [Serializable]
    [XmlRoot("Calls")]
    public class PhoneCallList : PagedList<PhoneCall>
    {
    }

    /// <summary>
    /// The PhoneCall object represents a connection between a telephone and Twilio. This may be inbound, when a person calls your application, or outbound when your application initiates the call.
    /// </summary>
    /// <remarks>
    /// A single call may contain multiple call "Segments", each represented as a Call element. For example, if a person dials your application, that's one call record.
    /// Then, if your application Dials another phone number, a new related call segment is created. Both have the same Sid, but different CallSegmentSids.
    /// For the initial Call, the CallSegmentSid is empty.
    /// </remarks>
    [Serializable]
    [XmlRoot("Call")]
    public class PhoneCall : BaseAccountInfo
    {

        #region Constructors

        /// <summary>
        /// Creates a new instance of the PhoneCall object.
        /// </summary>
        public PhoneCall() : base()
        {
        }

        /// <summary>
        /// Creates a new instance of the PhoneCall object.
        /// </summary>
        /// <param name="sid">A 34 character string that uniquely identifies this resource.</param>
        public PhoneCall(string sid) : base(sid)
        {
        }

        #endregion

        /// <summary>
        /// A 34 character string that uniquiely identifies a portion of a phone call.
        /// </summary>
        /// <remarks>
        /// For example, if you use the Dial verb during a call, you've created a new call segment. CallSegmentSid is an empty string for the initial call.
        /// </remarks>
        [XmlElement]
        public string CallSegmentSid { get; set; }

        /// <summary>
        /// The phone number that received/will receive this Call.
        /// </summary>
        /// <remarks>
        /// For incoming calls, it's one of your Twilio phone numbers. For outgoing calls, it's the person that you called. 
        /// Always presented as a 10 digit number, with no "decoration" (like dashes, parentheses, etc.)
        /// </remarks>
        [XmlElement]
        public string Called { get; set; }

        /// <summary>
        /// The OutgoingCallerID phone number that made/will make this Call.
        /// </summary>
        /// <remarks>
        /// For incoming calls, it's the person who called your Twilio phone number. For outgoing calls, it's the Caller you specified for the call. 
        /// Always presented as a 10 digit number, with no "decoration" (like dashes, parentheses, etc.)
        /// </remarks>
        [XmlElement]
        public string Caller { get; set; }

        /// <summary>
        /// If the call was inbound, this is the Sid of the IncomingPhoneNumber that received the call. 
        /// If the call was outgoing, it is the Sid of the OutgoingCallerId from which the call was placed.
        /// </summary>
        [XmlElement]
        public string PhoneNumberSid { get; set; }

        /// <summary>
        /// An integer representing the status of the call. 
        /// </summary>
        /// <remarks>
        /// 0 = Not Yet Dialed, 1 = In Progress, 2 = Complete, 3 = Failed - Busy, 4 = Failed - Application Error, 5 = Failed - No Answer
        /// </remarks>
        [XmlElement]
        [DefaultValue(0)]
        public int Status { get; set; }

        /// <summary>
        /// The timestamp of the start of the call, given in RFC 2822 format. 
        /// </summary>
        /// <remarks>
        /// If the call has not yet been dialed, this field will be empty.
        /// </remarks>
        [XmlElement("StartTime")]
        public string CallStartTime { get; set; }

        /// <summary>
        /// The timestamp of the end of the call, given in RFC 2822 format.
        /// </summary>
        /// <remarks>
        /// If the call did not complete successfully, this field will be empty.
        /// </remarks>
        [XmlElement("EndTime")]
        public string CallEndTime { get; set; }

        /// <summary>
        /// Duration is the length of the call in seconds.
        /// </summary>
        /// <remarks>
        /// This value is only populated for successfully completed calls. This will be an empty value for calls that are currently ongoing, that were busy, failed, or were not answered. 
        /// </remarks>
        [XmlElement]
        [DefaultValue(0)]
        public int Duration { get; set; }

        /// <summary>
        /// The charge for this call in USD.
        /// </summary>
        /// <remarks>
        /// Populated after the call is completed. Note, this value may not be immediately available. In a trial account, this value is not populated, since the call was free! 
        /// </remarks>
        [XmlElement]
        [DefaultValue(0.00)]
        public long Price { get; set; }

        /// <summary>
        /// A bitwise field for storing extra information about a call.
        /// </summary>
        /// <remarks>
        /// <para>Possible values are: 1 means the call was inbound, 2 means the call was initiated by the API, 4 means the call segment was initiated by a Dial verb.</para>
        ///These values may be OR'd together. For example, if you initiated a call via the API, the flags would equal 2. Then, if during that call you used the Dial verb to call another person, the second call segmenent would have Flag equal 6, indicating the the call was originally API initiated, and then the segement was Dial initiated. 
        /// </remarks>
        [XmlElement]
        [DefaultValue(0)]
        public int Flags { get; set; }

    }
}
